<!--订单管理-待处理订单-->
<template>
  <div class="video-list-manage-parent" ref="parentContainer">
    <!--操作表单区域-->
    <div class="option-parent" ref="optionParentContainer">
      <!--<el-row :gutter="0">-->
      <!--<el-col :span="4">-->
      <!--<el-select v-model="listTypeId" placeholder="查询类型选择">-->
      <!--<el-option-->
      <!--v-for="item in listTypes"-->
      <!--:key="item.id"-->
      <!--:label="item.name"-->
      <!--:value="item.id">-->
      <!--</el-option>-->
      <!--</el-select>-->
      <!--</el-col>-->
      <!--<el-col :span="4">-->
      <!--<el-input v-model="ordersn" placeholder="请输入订单号"></el-input>-->
      <!--</el-col>-->
      <!--<el-col :span="4">-->
      <!--<el-date-picker-->
      <!--v-model="dt1"-->
      <!--type="datetime"-->
      <!--placeholder="请选择开始时间">-->
      <!--</el-date-picker>-->
      <!--</el-col>-->
      <!--<el-col :span="4">-->
      <!--<el-date-picker-->
      <!--v-model="dt2"-->
      <!--type="datetime"-->
      <!--placeholder="请选择结束时间">-->
      <!--</el-date-picker>-->
      <!--</el-col>-->
      <!--<el-col :span="8">-->
      <!--<el-button type="primary" @click="queryArticleByBtn()">查询</el-button>-->
      <!--</el-col>-->
      <!--</el-row>-->
    </div>

    <!--数据表格区域-->
    <div v-bind:style="{height:tableHeight+'px',width:'100%'}" v-loading="loading">
      <el-table :data="orderData.agent_order_pending_list" border width="100%" height="100%">
        <el-table-column
          fixed
          label="订单号"
          prop="ordersn"
          min-width="110">
        </el-table-column>
        <el-table-column
          prop="dtb10"
          label="发起退款时间"
          min-width="110">
          <template slot-scope="scope">
            <p>{{genTime(scope.row.dtb10)}}</p>
          </template>
        </el-table-column>
        <el-table-column
          prop="sellername"
          label="商户"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="dt0"
          label="下单时间"
          min-width="140">
          <template slot-scope="scope">
            <p>{{genTime(scope.row.dt0)}}</p>
          </template>
        </el-table-column>
        <el-table-column
          prop="total_amount"
          label="订单金额"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="total_pay"
          label="支付总额"
          min-width="80">
        </el-table-column>
        <el-table-column
          prop="refundreason"
          label="退款原因"
          width="80">
        </el-table-column>
        <el-table-column
          prop="sellername"
          label="商户名称"
          min-width="80">
        </el-table-column>
        <el-table-column
          prop="sellersn"
          label="商户编号"
          min-width="80">
        </el-table-column>
        <el-table-column
          label="买家姓名"
          min-width="80">
          <template slot-scope="scope">
            <p>{{genBuyerSex(scope.row)}}</p>
          </template>
        </el-table-column>
        <el-table-column
          label="买家地址"
          min-width="80">
          <template slot-scope="scope">
            <p>{{genBuyerAddr(scope.row)}}</p>
          </template>
        </el-table-column>
        <el-table-column
          prop="buyermobile"
          label="买家手机号"
          min-width="110">
        </el-table-column>
        <el-table-column
          prop="buyermobile"
          label="申请仲裁"
          min-width="110">
          <template slot-scope="scope">
            <p>{{genOrderstate2(scope.row)}}</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="210">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleSellerWiner(scope.row)">
              商家胜
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleUserWiner(scope.row)">
              用户胜
            </el-button>
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="lookDetail(scope.row)">查看
              </el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--翻页区域-->
    <div class="pagination-parent" ref="paginationParentContainer">
      <el-pagination
        class="pagination-body"
        @current-change="handleCurrentChange"
        :page-size="limit"
        layout="total, prev, pager, next"
        :total="orderData.rowcount">
      </el-pagination>
    </div>

  </div>
</template>

<script>
  import CPageBase from "../fragment/CPageBase"
  import CRootBase from "../fragment/CRootBase"

  export default {
    data() {
      return {
        pathArr: [
          {path: "/", name: "首页"},
          {path: "/container/order_list", name: "待处理订单"},
        ],
        start: 1,
        limit: 20,
        orderData: "",
        loading: false,
      }
    },
    watch: {},
    mixins: [CPageBase, CRootBase],
    components: {},
    mounted() {

    },
    activated() {
      this.initCurrentPath();
      this.requestOrderData();
    },
    methods: {
      //初始化面包屑路径
      initCurrentPath() {
        this.$store.commit('changeCurrentLocation', this.pathArr);
      },

      //计算买家称呼
      genBuyerSex(item) {
          if(item.buyersex==="0"){
            return item.buyername + "  保密";
          }else if(item.buyersex==="1"){
            return item.buyername + "先生";
          }else if(item.buyersex==="2"){
            return item.buyername + "女士";
          }
      },

      //拼接买家地址
      genBuyerAddr(item) {
        return item.buyeraddr1 + item.buyeraddr2 + item.buyeraddr3;
      },

      //拼接图片地址
      genColumnImg(item) {
        return this.$utils.genImgURL(item.url);
      },

      //截取时间
      genTime(time) {
        return time.substring(0, time.length - 2);
      },

      //打开新增页面
      openPage() {
        this.$router.push("seller_add");
      },

      //查看详情
      lookDetail(item) {
        item.form="order_list_wait";
        this.$router.push({path: 'order_detail', query: item});
      },

      //仲裁状态
      genOrderstate2(item){
          if(item.orderstate2==="30"){
          return "未申请";
          }else if(item.orderstate2==="40"){
            return "已申请";
          }
      },


      //处理页面改变事件
      handleCurrentChange(currentPage) {
        this.start = this.start + this.limit;
        this.requestOrderData();
      },

      //点击查询按钮
      queryArticleByBtn() {
        this.start = 1;
        this.limit = 20;
        this.requestOrderData();
      },

      //转换时间格式
      getTimeDt(dt, sign) {
        let nowDate = "";
        if (this.$utils.isEmpty(dt) && sign === 1) {
          nowDate = new Date();
          nowDate.setMonth(nowDate.getMonth() - 1);
        } else if (this.$utils.isEmpty(dt)) {
          nowDate = new Date();
        } else {
          nowDate = new Date(dt);
        }
        let year1 = nowDate.getFullYear();
        let month1 = nowDate.getMonth() + 1;
        let date1 = nowDate.getDate();
        let hours1 = nowDate.getHours();
        let minutes1 = nowDate.getMinutes();
        let millis1 = nowDate.getMilliseconds();
        if (month1 < 10) {
          month1 = "0" + month1;
        }
        if (date1 < 10) {
          date1 = "0" + date1;
        }
        if (hours1 < 10) {
          hours1 = "0" + hours1;
        }
        if (minutes1 < 10) {
          minutes1 = "0" + minutes1;
        }
        if (millis1 < 10) {
          millis1 = "0" + millis1;
        }
        millis1 = millis1 + "".substring(0, 1);
        return year1 + "-" + month1 + "-" + date1 + " " + hours1 + ":" + minutes1 + ":" + millis1;
      },

      //获取订单
      requestOrderData() {
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_order_pending_list");
        parameter.append("pageno", this.start);
        parameter.append("pagesize", this.limit);
        let that = this;
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.orderData = data;
        });
      },

      //商家胜出提示框
      handleSellerWiner(item,) {
        let that = this;
        this.$confirm('确认商家在本轮裁决胜出吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.confireWhoWiner(item, 1);
        }).catch(() => {
        });
      },

      //用户胜出提示框
      handleUserWiner(item,) {
        let that = this;
        this.$confirm('确认用户在本轮裁决胜出吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.confireWhoWiner(item, 0);
        }).catch(() => {
        });
      },

      //裁决请求
      confireWhoWiner(item, sign) {
        let that = this;
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_order_judge");
        parameter.append("orderid", item.orderid);
        parameter.append("judge_state", sign);
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.$message({type: 'success', message: '裁决成功!'});
          that.requestOrderData();
        });
      },
    }
  }
</script>

<style lang="scss" scoped="" type="text/scss" src="../../assets/style/list-type-pages.scss">

</style>

